package emulator.support;

import emulator.hardware.HwByte;
import emulator.hardware.HwWord;
import emulator.util.MemoryPtr;

public class AbsoluteXOperandEval implements OperandEval {

	MemoryPtr instruction;
	
	public AbsoluteXOperandEval(MemoryPtr ptr) {
		instruction = ptr;
	}

	@Override
	public String getDetails(CpuState cpu_state) {
		int old_address = instruction.getAddress();
		int reg_x = cpu_state.getValue("X");
		int operand = instruction.getWordOp();
		instruction.setAddress(operand);
		String result = "($" + new HwWord(operand) + " + $" + new HwByte(reg_x) + ") -> $" + new HwByte(instruction.getByteOp(reg_x));
		instruction.setAddress(old_address);
		return result;
	}

	@Override
	public boolean isAddress() {
		return true;
	}

	@Override
	public int getAddress(CpuState cpu_state) {
		return instruction.getWordOp()+cpu_state.getValue("X");
	}

	@Override
	public boolean isIndirect() {
		return false;
	}
}
